import 'package:enjoy_plus_hm/pages/house/house_list.dart';
import 'package:flutter/material.dart';

class HouseItem extends StatefulWidget {
  HouseItem({super.key, required this.houseInfo});
  // 房屋列表项
  Map houseInfo;

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  // 房屋列表项
  Map houseInfo = {};

  @override
  void initState() {
    // 将HouseItem中的houseInfo赋值给当前对象_HouseItemState的houseInfo属性
    houseInfo = widget.houseInfo;
    super.initState();
  }

// 创建标签widget
  Widget tagBuilder(int status) {
    // status 1 审核成功 2 审核中 3 审核失败
    List tagList = [
      {},
      {
        'title': '审核成功',
        'bgColor': const Color.fromARGB(58, 41, 14, 165),
        'textColor': Color.fromARGB(255, 85, 145, 175)
      },
      {
        'title': '审核中',
        'bgColor': const Color.fromARGB(47, 8, 233, 165),
        'textColor': Color.fromARGB(255, 38, 54, 62)
      },
      {
        'title': '审核失败',
        'bgColor': const Color.fromARGB(49, 200, 94, 7),
        'textColor': Color.fromARGB(255, 223, 219, 7)
      },
    ];
    // 创建标签widget
    return Container(
        padding: const EdgeInsets.only(left: 5, right: 5, top: 2, bottom: 2),
        decoration: BoxDecoration(
            color: tagList[status]['bgColor'],
            borderRadius: BorderRadius.circular(5)),
        child: Text('${tagList[status]['title']}',
            style: TextStyle(color: tagList[status]['textColor'])));
  }

  @override
  Widget build(BuildContext context) {
    // 添加页面跳转
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, '/house_detail', arguments: houseInfo);
      },
      child: Container(
          padding: const EdgeInsets.all(10),
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          child: Column(
            children: [
              Row(
                children: [
                  Expanded(child: Text('${houseInfo['point']}')),
                  const Spacer(),
                  tagBuilder(houseInfo['status']),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  Text(
                    '房间号',
                    style: TextStyle(color: Colors.grey),
                  ),
                  Spacer(),
                  Expanded(
                      child: Text(
                    "${houseInfo['building']}栋${houseInfo['room']}室",
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  Text(
                    '业主',
                    style: TextStyle(color: Colors.grey),
                  ),
                  Spacer(),
                  Expanded(
                      child: Text(
                    '${houseInfo['name']}',
                    textAlign: TextAlign.right,
                  )),
                ],
              ),
            ],
          )),
    );
  }
}
